package com.alipay.service.impl;

import com.alipay.common.ServerResponse;
import com.alipay.dao.UserMapper;
import com.alipay.entity.User;
import com.alipay.service.IUserService;
import com.alipay.util.MD5Util;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Yancy on 2019/11/9.
 */
@Service("iUserService")
public class UserServiceImpl implements IUserService{

    @Autowired
    private UserMapper userMapper;

    public ServerResponse<User> login(String username,String password){
        //判断用户名是否存在
        int resultCount = userMapper.checkName(username);
        if(resultCount == 0){
            return ServerResponse.createByErrorMessage("用户名不存在");
        }

        //String md5Password = MD5Util.MD5EncodeUtf8(password);

        User user = userMapper.selectLogin(username,password);

        if(user == null){
            return ServerResponse.createByErrorMessage("密码错误");
        }
        user.setPassword(StringUtils.EMPTY);
        return ServerResponse.createBySuccess("登录成功",user);
    }
}
